﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using White.Core.UIItems.ListViewItems;
using White.Core.AutomationElementSearch;
using System.Windows.Automation;
using White.Core.UIItems;

namespace SilverlightLesson1
{
    public class AutomationHelper
    {
        public static ListViewHeader GetGridHeader(ListView test)
        {
            // Get the autotmation element finder 
            AutomationElementFinder finder = new AutomationElementFinder(test.AutomationElement);

            //get the header automation element 
            AutomationElement headerElement = finder.Descendant(AutomationSearchCondition.ByControlType(ControlType.Header));


            ListViewHeader header = new ListViewHeader(headerElement, test.ActionListener);
            return header;
        }

        public static ListViewCell GetGridCell(string ColumnName, ListView grdControl, List<AutomationElement> objLstAutomationElementCells)
        {

            //var columnHeaders = test.AutomationElement.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, "GridViewHeaderRow"));
            //var HeaderElement = test.GetElement(White.Core.UIItems.Finders.SearchCriteria.ByControlType(ControlType.Header));
            ListViewHeader header = AutomationHelper.GetGridHeader(grdControl);

            //Create a new listviewcells collection for all the cells in the grid view new row
            ListViewCells cells = new ListViewCells(objLstAutomationElementCells, grdControl.ActionListener, header);

            //Get the current editable cell based on parameter
            ListViewCell cell = cells[ColumnName];
            return cell;
        }

    }
}
